Fix inside-out polygon artifact in ObliqueMercator projection#2651
Open
jackbenn wants to merge 1 commit intoSciTools:mainfrom
Open
Fix inside-out polygon artifact in ObliqueMercator projection#2651jackbenn wants to merge 1 commit intoSciTools:mainfrom
jackbenn wants to merge 1 commit intoSciTools:mainfrom
Conversation
When a polygon crosses the projection cut line (the antipodal great circle), _attach_lines_to_boundary can produce an exterior ring that traces the *complement* of the intended shape while still carrying the correct CCW/CW winding flag. The ring is therefore classified as exterior by _rings_to_multi_polygon, and sgeom.Polygon(exterior_ring) produces a polygon covering ~80-95% of the projection domain — causing ocean areas to render as land colour. The fix: before processing each exterior ring in the normal holes-slurping loop, check whether the ring's polygon area exceeds half the projection domain area. If it does, the ring is inverted; replace it with boundary_poly.difference(ring_polygon) to recover the correct shape and continue to the next ring. Regression test added in TestMisc.test_oblique_mercator_no_inverted_land using 50m Natural Earth land data (the bug only manifests at 50m or finer; AdaptiveScaler picks 50m when the map extent is small enough to require more detail). Fixes rendering of land/ocean features in ObliqueMercator projections over the North Pacific (e.g. a Seattle–Tokyo strip map), where several large land masses (Alaska, Chukotka, Kamchatka) cross the cut line. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale
When a polygon crosses the projection cut line (the antipodal great circle), _attach_lines_to_boundary can produce an exterior ring that traces the complement of the intended shape while still carrying the correct CCW/CW winding flag. The ring is therefore classified as exterior by
_rings_to_multi_polygon, andsgeom.Polygon(exterior_ring)produces a polygon covering ~80-95% of the projection domain — causing ocean areas to render as land colour.The fix: before processing each exterior ring in the normal holes-slurping loop, check whether the ring's polygon area exceeds half the projection domain area. If it does, the ring is inverted; replace it with
boundary_poly.difference(ring_polygon)to recover the correct shape and continue to the next ring.Regression test added in
TestMisc.test_oblique_mercator_no_inverted_landusing 50m Natural Earth land data (the bug only manifests at 50m or finer;AdaptiveScalerpicks 50m when the map extent is small enough to require more detail).Fixes rendering of land/ocean features in ObliqueMercator projections over the North Pacific (e.g. a Seattle–Tokyo strip map), where several large land masses (Alaska, Chukotka, Kamchatka) cross the cut line.
This is a fix for #2650
Implications
This should have no effect beyond fixing the immediate bug.